//
// Created by xili on 2024/9/23 19:52.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

//枚举左维护右
class Solution {
public:
    int minimumCardPickup(vector<int> &cards) {
        int n = cards.size();
        int ans = INT32_MAX;
        unordered_map<int, int> ump;
        for (int i = 0; i < n; i++) {
            if (ump.count(cards[i])) {
                ans = min(ans, i - ump[cards[i]] + 1);
            }
            ump[cards[i]] = i;
        }
        return ans == INT32_MAX ? -1 : ans;
    }
};